package com.bravo.other.geoid;

import java.util.Map;

/**
 * Calculate geoid height for a specific location
 * 
 * @author bravo
 */
public class CalculateSpecificLocation {
    
    public static void main(String[] args) {
        // Specific coordinates: longitude 120.18562, latitude 30.85816
        double longitude = 120.18562;  // longitude
        double latitude = 30.85816;    // latitude
        
        System.out.println("=== Geoid Height Calculation for Specific Coordinates ===");
        System.out.printf("Coordinates: Longitude %.5f°, Latitude %.5f°\n", longitude, latitude);
        System.out.println();
        
        // 1. Calculate using EGM2008 model
        try {
            double geoidHeightEGM2008 = GeoidHeightCalculator.calculateEGM2008(latitude, longitude);
            System.out.printf("EGM2008 Model Result: %.6f meters\n", geoidHeightEGM2008);
        } catch (Exception e) {
            System.err.println("EGM2008 model calculation failed: " + e.getMessage());
        }
        
        // 2. Calculate using EGM96 model
        try {
            double geoidHeightEGM96 = GeoidHeightCalculator.calculateEGM96(latitude, longitude);
            System.out.printf("EGM96 Model Result: %.6f meters\n", geoidHeightEGM96);
        } catch (Exception e) {
            System.err.println("EGM96 model calculation failed: " + e.getMessage());
        }
        
        // 3. Calculate using interpolation method
        try {
            Map<GeoidHeightCalculator.Coordinate, Double> controlPoints = 
                GeoidHeightCalculator.createSampleControlPoints();
            double geoidHeightInterpolation = GeoidHeightCalculator.calculateByInterpolation(
                latitude, longitude, controlPoints);
            System.out.printf("Interpolation Method Result: %.6f meters\n", geoidHeightInterpolation);
        } catch (Exception e) {
            System.err.println("Interpolation method calculation failed: " + e.getMessage());
        }
        
        // 4. Use advanced EGM2008 calculator (different degrees)
        try {
            double advanced5 = AdvancedGeoidCalculator.calculateEGM2008Complete(latitude, longitude, 5);
            double advanced10 = AdvancedGeoidCalculator.calculateEGM2008Complete(latitude, longitude, 10);
            double advanced20 = AdvancedGeoidCalculator.calculateEGM2008Complete(latitude, longitude, 20);
            double advanced30 = AdvancedGeoidCalculator.calculateEGM2008Complete(latitude, longitude, 30);
            
            System.out.println("\nAdvanced EGM2008 Results (Different Degrees):");
            System.out.printf("  5 degrees:  %.6f meters\n", advanced5);
            System.out.printf("  10 degrees: %.6f meters\n", advanced10);
            System.out.printf("  20 degrees: %.6f meters\n", advanced20);
            System.out.printf("  30 degrees: %.6f meters\n", advanced30);
            
        } catch (Exception e) {
            System.err.println("Advanced EGM2008 calculation failed: " + e.getMessage());
        }
        
        // 5. Calculate gradient and curvature
        try {
            double[] gradient = AdvancedGeoidCalculator.calculateGeoidGradient(latitude, longitude, 0.001);
            double[][] curvature = AdvancedGeoidCalculator.calculateGeoidCurvature(latitude, longitude, 0.001);
            
            System.out.println("\nGradient Analysis:");
            System.out.printf("  Latitude gradient (dN/dlat): %.6f m/°\n", gradient[0]);
            System.out.printf("  Longitude gradient (dN/dlon): %.6f m/°\n", gradient[1]);
            System.out.printf("  Gradient magnitude: %.6f m/°\n", Math.sqrt(gradient[0]*gradient[0] + gradient[1]*gradient[1]));
            
            System.out.println("\nCurvature Analysis:");
            System.out.printf("  d²N/dlat²:    %.6f m/°²\n", curvature[0][0]);
            System.out.printf("  d²N/dlatdlon: %.6f m/°²\n", curvature[0][1]);
            System.out.printf("  d²N/dlon²:    %.6f m/°²\n", curvature[1][1]);
            
        } catch (Exception e) {
            System.err.println("Gradient and curvature calculation failed: " + e.getMessage());
        }
        
        // 6. Compare with online tool results
        System.out.println("\n=== Result Comparison Analysis ===");
        System.out.println("Online tool result: approximately 10 meters");
        System.out.println("Note: Online tools may use different models or coordinate systems");
        System.out.println();
        
        // 7. Accuracy explanation
        System.out.println("=== Accuracy Explanation ===");
        System.out.println("• EGM2008 Model: ±0.1-0.2m accuracy, suitable for high-precision measurement");
        System.out.println("• EGM96 Model: ±0.5-1.0m accuracy, suitable for general engineering applications");
        System.out.println("• Interpolation Method: accuracy depends on control point density and distribution");
        System.out.println("• Advanced EGM2008: supports different degrees, higher degrees mean higher accuracy");
        System.out.println();
        
        System.out.println("=== Application Recommendations ===");
        System.out.println("• If online tool result is around 10 meters, recommend using EGM2008 model");
        System.out.println("• For engineering applications, EGM96 model is usually sufficient");
        System.out.println("• For high-precision applications, recommend EGM2008 model");
        System.out.println("• In practice, consider model updates and data timeliness");
    }
}
